<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加地址</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/Product/css/page_tianjiadizhi.css">
    <link rel="stylesheet" href="__PUBLIC__/Product/css/lib/animate.css">
    <script src="__PUBLIC__/Product/js/lib/flexible.js"></script>
</head>
<body style="background-color: #f4f4f4;">
    <div class="edit_address_box">
        <!-- 头部 -->
        <div class="edit_address_header">
        	 <p><img src="__PUBLIC__/Product/img/fanhui.png" onclick="window.location.href =  document.referrer"/></p>
            <p>添加地址</p>
           
            <p>添加</p>
           
        </div>
        <!-- 内容 -->
        <div class="edit_address_content">
        	<ul>
        		<li>
        			<label for="">收货人</label>
        			<input type="text" class="name" placeholder="请收入收货人实名" />
        		</li>
        		<li>
        			<label for="">手机号</label>
        			<input type="number" id="telphone" maxlength="11" placeholder="请输入手机号码" />
        		</li>
        		<li>
        			<label for="">地区</label>
        			<input type="text" class="county" placeholder="选择所在地区" />
        			
        		</li>
        		<li>
        			<label for="">街道</label>
        			<input type="text" class="street" placeholder="所在街道" />
        			
        		</li>
        		<li>
        			<label for="">邮编</label>
        			<input type="text" class="zip_code" placeholder="地区邮编" />
        			
        		</li>
        		<li>
        			<label for="">详细地址</label>
    				<textarea name="" rows="5" cols="30" class="detail" placeholder="请输入详细地址"></textarea>
        		</li>
        		<li>
        			<span style="font-weight: 600;">设为默认地址</span>
        			<input type="checkbox" class="check" id="check"/>
        		</li>
        	</ul>
        </div>
       
    </div>

</body>
</html>
<script src="__PUBLIC__/Product/js/lib/jquery3.2.1.js"></script>
<script>
	$(function(){
		$(".edit_address_header p:nth-child(3)").bind("click", function() {
			var name=$(".name").val();
			var telphone=document.getElementById("telphone").value;
			var country=$(".county").val();
			var detail=$(".detail").val();
			var street = $(".street").val();
			var zip_code = $(".zip_code").val();
			var state;
			if($(".check").get(0).checked){
				state = 1;
			}else{
				state = 2;
			}
			//判断输入框的内容是否为空
			var myreg = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
			if(name == "") {
				console.log("姓名不能为空!");
			} else if(telphone == '') {
				console.log("电话不能为空!");
			} else if(telphone.length != 11) {
				console.log("请输入有效的手机号");
			} else if(!myreg.test(telphone)) {
				console.log("请输入有效的手机号!");
			}   else if(country == "") {
				console.log("请输入地区名称");
			} else if(street == "") {
				console.log("请输入街道名称");
			}else if(zip_code == "") {
				console.log("请输入邮编");
			}
			else if(detail == "") {
				console.log("请输入详细地址");
			} else {
				$.ajax({
					type: "post",
					url: "http://a.91jfk.com/Product/Address/add_address",
					async: true,
					data: {
						name:name,
						tel:telphone,
						area:country,
						address:detail,
						state:state,
						street:street,
						zip_code:zip_code
					},
					dataType: 'json',
					success: function(res) {
						console.log(res);
						if(res.code == '1') {
							console.log("添加成功");
							location.href='adress_list.html';
						} 
					},
					error: function(err) {}
				});
			}
		});
	});
</script>


